#include <iostream>
#include <vector>

using namespace std;
// 9.回文数
// 给你一个整数 x ，如果 x 是一个回文整数，返回 true ；否则，返回 false 。

class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0)
            return false;
        // x 为 0 时，不能忘记了
        if(x == 0)
            return true;

        int c = 0;
        vector<char> tmparr;
        while (x) {
            tmparr.push_back(x % 10);
            x /= 10;
        }

        size_t i = 0, j = tmparr.size()-1;
        while (i < j && tmparr[i] == tmparr[j]) {
            i++; j--;
        }
        if(i >= j)   // 这里应该是i >= j，不是i == j
            return true;
        else
            return false;
    }
};

int main() {
    int x1 = 121;
    cout << "x = " << x1 << " : " << boolalpha << Solution().isPalindrome(x1) << endl;   // true

    int x2 = -121;
    cout << "x = " << x2 << " : " << boolalpha << Solution().isPalindrome(x2) << endl;   // false

    int x3 = 10;
    cout << "x = " << x3 << " : " << boolalpha << Solution().isPalindrome(x3) << endl;   // false

    int x4 = 11;
    cout << "x = " << x4 << " : " << boolalpha << Solution().isPalindrome(x4) << endl;   // true

    int x5 = 0;
    cout << "x = " << x5 << " : " << boolalpha << Solution().isPalindrome(x5) << endl;   // true
    return 0;
}
